package com.xkcoding.task.controller;

import com.alibaba.fastjson.JSON;
import com.xkcoding.task.config.ArtemisPostTest;
import com.xkcoding.task.dto.BackDataDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/third")
public class ThirdController {

    @PostMapping(value = "/back")
    public String local(@RequestBody BackDataDto backDataDto) {
        log.info("receiver back request ：{}", JSON.toJSONString(backDataDto));
        String message = backDataDto.getData().getMessage();
        try {
            if (message.contains("0")) {
                ArtemisPostTest.doorController(2);
            } else if (message.contains("1")) {
                ArtemisPostTest.doorController(1);
            }
        } catch (Exception e) {
            log.error("", e);
            e.printStackTrace();
        }
        log.info("back success!!!!");
        return "ok";
    }
}
